/**
 * Created by benben on 14-9-24.
 */
$(".ui-frozen-cover").cover({
    callback:function(type,obj){
        switch(type){
            case "show":
                covershow(obj);
                break;
            case "hide":
                coverhide(obj);
                break;
            case "hidden":
                coverhidden(obj);
                break;
            case "shown":
                covershown(obj);
                break;
        }

    }
});
function covershow(cover){
    if(!cover._isShown){
        var title=cover.currentTrigger.find('.title'),
            index=$(".item").index(cover.currentTrigger);

        title.css({
            '-webkit-transform':'translateY('+(cover.position.screenHeight/2-title.offset().top-300)+'px)'
        });
        $('.info').eq(index).css({
            "-webkit-transition-delay":".5s"
        });
        $('.info').eq(index).addClass('show');

        if(index == 0){
            $('#activity').load("d.html");
        }else if(index == 2){
            if($('#customers').html().length == 0){
                $('#customers').load("customers.html",function(){
                    loaded ();
                    $.getJSON('/customer/customers', function(json){

                        var customers = eval(json.data);
                        for(var i = 0; i < customers.length; i++){
                            var customer = customers[i];
                            var height = 30;

                            var html = '<div class="boxTitle">'+customer['customerName']+'</div>';

                            if(customer['customerNo'].length > 0){
                                html += '<div>客户编号：'+customer['customerNo']+'</div>';
                                height += 18;
                            }
                            if(customer['grade'].length > 0){
                                html += '<div>客户级别：'+customer['grade']+'</div>';
                                height += 18;
                            }
                            if(customer['phone'].length > 0){
                                html += '<div>联系电话：'+customer['phone']+'</div>';
                                height += 18;
                            }
                            if(customer['fax'].length > 0){
                                html += '<div>传真：'+customer['fax']+'</div>';
                                height += 18;
                            }
                            if(customer['email'].length > 0){
                                html += '<div>邮箱：'+customer['email']+'</div>';
                                height += 18;
                            }
                            if(customer['webSite'].length > 0){
                                html += '<div>网站：'+customer['webSite']+'</div>';
                                height += 18;
                            }
                            if(customer['address'].length > 0) {
                                html += '<div>联系地址：' + customer['address'] + '</div>';

                                var size = customer['address'].length + 5;

                                height += 18*(size/12+1);
                            }

                            html = '<div style="height:'+height+'px" class="box">'+html+'</div>';

                            $('.container').append(html);
                        }
                    })
                });
            }
        }
    }
};
function coverhide(cover){
    var title=cover.currentTrigger.find('.title'),
        index=$(".item").index(cover.currentTrigger);

    title.css({
        '-webkit-transform':'translateY(0px)'
    });
    $('.info').eq(index).css({
        "-webkit-transition-delay":"0s"
    });
    $('.info').eq(index).removeClass('show');
};
function covershown(cover){
    $('.close').show();
};
function coverhidden(){
    $('.close').hide();
};


function loaded () {
    var myScroll = new IScroll('#wrapper', {
        scrollX: false,
        scrollY: true,
        mouseWheel: true
    });
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);